package com.cy1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class MapDemo3 {
    public static void main(String[] args) {
        HashMap<String, String> map = new HashMap<>();
        map.put("chenyong","meilv");
        map.put("shuangge","shi chenyong");
        map.put("yuanxiang","aichneyong");
//        System.out.println(map.get("chenyong"));
        //MAP集合遍历方式1，通过键去找值，可形象的理解为通过丈夫去找妻子
        Set<String> key = map.keySet();
        for (String s : key) {
            String s1 = s;
            System.out.println(s1+","+map.get(s1));
        }
        System.out.println("--------------");
        //MAP集合遍历方式2：通过获取键值对对象的方法遍历集合,可以形象的理解为通过结婚证去找到丈夫和妻子
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            Map.Entry<String, String> entry1 = entry;
            System.out.println(entry.getKey()+","+entry1.getValue());
        }

    }
}
